$(function () {
  $('.btn-primary').click(function () {
    // 手机正则验证  /^ (13 [0-9]|14 |15 [0-3,5-9]|16 |17 |18 [0-9]|19)d {8}$/
    const iphoneNum = $('.login-form .ipt:eq(0)').find('input').val()
    const reg = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
    if (!reg.test(iphoneNum)) return alert('请输入正确的手机号')
    // 密码非空验证
    const pwd = $('.login-form .ipt:eq(1)').find('input').val()
    if (!pwd.trim()) return alert('请输入密码')
    // 二次密码验证
    const repwd = $('.login-form .ipt:eq(2)').find('input').val()
    console.log(repwd)
    if (pwd !== repwd) return alert('两次输入密码不一致')
    $.ajax({
      method: 'post',
      url: 'http://127.0.0.1:8060/index/reg',
      data: {
        mobile: iphoneNum - 0,
        password: pwd,
      },
      success: function (res) {
        console.log(res)
        if (res.errno !== 0) return
        localStorage.setItem('userToken', res.data.token)
        location.href = 'login.html'
      },
    })
  })
})
